package com.zw.yzk.kabu.data.repository;

import com.zw.yzk.kabu.data.cache.store.ImInfoStore;
import com.zw.yzk.kabu.data.network.ServiceGenerator;
import com.zw.yzk.kabu.data.network.entity.ImInfoEntity;
import com.zw.yzk.kabu.data.network.service.ImInfoService;
import com.zw.yzk.kabu.data.network.task.ImInfoTask;
import com.zw.yzk.kabu.data.network.task.Task;

import javax.inject.Inject;

import rx.Observable;
import rx.functions.Func1;

/**
 * Created by zhanwei on 2016/12/24.
 */

public class GetImInfoRepository extends CommonRepository {

    @Inject
    ImInfoStore imInfoStore;

    @Inject
    public GetImInfoRepository() {

    }

    @Override
    protected Observable connectServer(Task task) {
        ImInfoService service = ServiceGenerator.createService(ImInfoService.class);
        ImInfoTask commentTask = (ImInfoTask) task;

        return service.getImInfo(commentTask.userId);
    }

    @Override
    protected Func1<ImInfoEntity, Observable> getServerData() {
        return new Func1<ImInfoEntity, Observable>() {
            @Override
            public Observable call(ImInfoEntity entity) {
                imInfoStore.refresh(entity);
                return Observable.just(entity);
            }
        };
    }

}
